package com.qfedu;

import com.qfedu.dao.ProjectDao;
import com.qfedu.model.Project;
import com.qfedu.dao.*;
import com.qfedu.model.*;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Demo {
    SqlSession sqlSession;
    ProjectDao projectDao;
    BranchDao branchDao;
    ContractorDao contractorDao;
    DeveloperDao developerDao;
    ItemDao itemDao;
    StageDao stageDao;
    SubitemDao subitemDao;
    TaskplanDao taskplanDao;
    @Before
    public void init(){
        try {
            //加载配置文件
            InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
            //构建工厂建造类对象
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            //创建工厂类对象
            SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resourceAsStream);
            //创建sqlsession
            sqlSession= sqlSessionFactory.openSession(true);
            projectDao= sqlSession.getMapper(ProjectDao.class);
            branchDao= sqlSession.getMapper(BranchDao.class);
            contractorDao = sqlSession.getMapper(ContractorDao.class);
            developerDao = sqlSession.getMapper(DeveloperDao.class);
            itemDao = sqlSession.getMapper(ItemDao.class);
            stageDao = sqlSession.getMapper(StageDao.class);
            subitemDao = sqlSession.getMapper(SubitemDao.class);
            taskplanDao = sqlSession.getMapper(TaskplanDao.class);

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @After
    public void distory(){
        sqlSession.close();
    }

    @Test
    public void demo01(){
        List<Project> list = projectDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo02(){
        List<Branch> list = branchDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo03(){
        List<Contractor> list = contractorDao.findAll();
        list.forEach(System.out::println);
    }
    @Test
    public void demo04(){
        List<Developer> list = developerDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo05(){
        List<Item> list = itemDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo06(){
        List<Stage> list = stageDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo07(){
        List<Subitem> list = subitemDao.findAll();
        list.forEach(System.out::println);
    }

    @Test
    public void demo08(){
        List<Taskplan> list = taskplanDao.findAll();
        list.forEach(System.out::println);
    }


}
